package com.jumi.microservice.stock.controller;

import com.google.common.collect.Lists;
import com.jumi.microservice.common.base.BaseController;
import com.jumi.microservice.common.base.dto.ResponseResult;
import com.jumi.microservice.common.page.TableDataInfo;
import com.jumi.microservice.material.domain.JmDictDTO;
import com.jumi.microservice.material.service.JmDictService;
import com.jumi.microservice.stock.api.dto.CommodityMaterialStockDTO;
import com.jumi.microservice.stock.api.impl.StockApiImpl;
import com.jumi.microservice.stock.domain.StockDTO;
import com.jumi.microservice.stock.domain.StockDetailDTO;
import com.jumi.microservice.stock.domain.StockOccupy4WarehouseDTO;
import com.jumi.microservice.stock.dto.StockMaterialRequest;
import com.jumi.microservice.stock.dto.StockMaterialResponse;
import com.jumi.microservice.stock.service.StockService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description
 * @ClassName StockTestController
 * @Author Abel Yang
 * @Date 2020/8/28/028 17:15
 **/
@RestController
@RequestMapping("/test")
public class StockTestController extends BaseController {

    @Resource
    private StockApiImpl stockApiImpl;

    @Resource
    private StockService stockService;

    @Resource
    private JmDictService jmDictService;

    @GetMapping("/getMaterialStockByMaterialIds")
    public ResponseResult<List<CommodityMaterialStockDTO>> getMaterialStockByMaterialIds() {
        List<Long> materialIds = Lists.newArrayList();
        materialIds.add(2L);

        ResponseResult<List<CommodityMaterialStockDTO>> jmStockMaterialList = stockApiImpl.getMaterialStockByMaterialIds(materialIds);

        return jmStockMaterialList;
    }

    @GetMapping("/inStock")
    public ResponseResult<Boolean> inStock() {
        StockDTO stockDTO = new StockDTO();
        stockDTO.setGoodsId(1L);
        stockDTO.setGoodsCode("1011110");
        stockDTO.setInStockTotalNum(20);
        stockDTO.setInStockDamageTotalNum(0);
        stockDTO.setWarehouseId(1L);
        stockDTO.setUpdateBy("哈哈哈");

        StockDetailDTO stockDetailDTO = new StockDetailDTO();
        stockDetailDTO.setMaterialId(1L);
        stockDetailDTO.setInStockNum(20);
        stockDetailDTO.setMaterialCode("22222");
        stockDetailDTO.setInStockDamageNum(0);
        List<StockDetailDTO> stockDetailDTOList = Lists.newArrayList();
        stockDetailDTOList.add(stockDetailDTO);
        stockDTO.setStockDetailDtoList(stockDetailDTOList);

        return stockService.inStock(stockDTO);
    }

    @GetMapping("/occupyStock")
    public ResponseResult<Boolean> occupyStock() {
        StockOccupy4WarehouseDTO stockDTO = new StockOccupy4WarehouseDTO();
        stockDTO.setMaterialId(1L);
        stockDTO.setWarehouseId(6L);
        stockDTO.setOccupyNum(1);
        stockDTO.setUpdateBy("哈哈哈");

        ResponseResult<Boolean> ret = stockService.occupyStock(stockDTO);
        return ret;
    }

    @GetMapping("/getDict")
    public ResponseResult getDict() {

        List<JmDictDTO> jmDictDTOList = jmDictService.getStockChangeTypes();

        return ResponseResult.success();
    }

    @PostMapping("/occupyStockRelease4AfterSaleOrder")
    @ApiOperation("test/occupyStockRelease4AfterSaleOrder")
    public ResponseResult getStockMaterialListByPage(StockOccupy4WarehouseDTO dto) {
        dto.setIsDamage(false);
        dto.setMaterialId(209L);
        dto.setOccupyNum(1);
        dto.setOrderSn("BF21011509362337088");
        dto.setWarehouseId(14L);
        dto.setChangeType(9);
        return stockService.occupyStockRelease4AfterSaleOrder(dto);
    }
}
